#include "tools.cpp"

class Solution {
  public:
    string countAndSay(int n) {
        std::string cur = "1";
        for (int i = 1; i < n; ++i) {
            cur = get_next(cur);
        }
        return cur;
    }

    string get_next(string cur) {
        std::string next;
        for (int i = 0; i < cur.size();) {
            int j = i;
            while (j < cur.size() and cur[j] == cur[i]) ++j;
            next.push_back(static_cast<char>(j - i + '0'));
            next.push_back(cur[i]);
            i = j;
        }
        return next;
    }
};

int main() {
    Solution s;
    for (int i = 1; i < 31; ++i) {
        std::cout << s.countAndSay(i) << std::endl;
    }
}
